package com.nxk.modules.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nxk.modules.content.dao.ConHonorDao;
import com.nxk.modules.content.entity.ConHonor;
import com.nxk.modules.content.service.ConHonorService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ConHonorServiceImpl extends ServiceImpl<ConHonorDao, ConHonor> implements ConHonorService {


    @Override
    @Transactional(readOnly = false)
    public boolean save(ConHonor conHonor) {
        if (StringUtils.isNotBlank(conHonor.getId())) {
            return super.updateById(conHonor);
        } else {
            return super.save(conHonor);
        }
    }

    @Override
    public IPage<ConHonor> page(ConHonor conHonor) {
        Page<ConHonor> page = new Page<ConHonor>(conHonor.getPageNo(), conHonor.getPageSize());
        QueryWrapper<ConHonor> queryWrapper = new QueryWrapper<ConHonor>();
        if (StringUtils.isNotBlank(conHonor.getHonorTitle())) {
            queryWrapper.lambda().like(ConHonor::getHonorTitle, conHonor.getHonorTitle());
        }
        queryWrapper.orderByAsc("sort").in("status", 1, 2);
        IPage<ConHonor> result = super.page(page, queryWrapper);
        return result;

    }

    @Override
    @Transactional(readOnly = false)
    public boolean deleteById(String id) {
        return super.removeById(id);
    }

}
